<?php
class form {
		function __contstruct() {
			
			
		}
		function __destruct() {
			
			
		}	
		function getContents($filename) {
			
			if (is_file($filename)) {
				ob_start();
				//$_settings=$row;
				include $filename;
			return ob_get_clean();
			}
			return true;
		}
		function include_form($json_str) {
			$json = json_decode($json_str,true);
			$token=$json['token'];
			$data = new database();
			$data->db(DATABASE)->collection('forms');
			$data->criteria(array('token'=>$token));
			$row=$data->findOne();
			$data->close();
			$f_class=($row['inline']==1) ? 'inline' : '';
			$output='<form class="'.$f_class.'" method="'.$row['method'].'" enctype="'.$row['enctype'].'" action="/forms/'.md5((string)$row['_id']).'/">';
			$output.='<input type="hidden" class="settings" name="settings" value=\'{"buttonWaitingValue":"'.$row['button_waiting_value'].'","updateNode":"#response"}\' />';
			$output.='<input type="hidden" name="token" id="token_'.$row['token'].'" value="'.$row['token'].'" />';
			$output.=$this->getContents($_SERVER['DOCUMENT_ROOT'].'/inc/form_'.$token.'.php');
			$output.='</form><!-- End form -->';
			$output.='<div id="response" style="display:none;"></div>';
			return $output;
		}
		function include_logic($json_str) {
			$json = json_decode($json_str,true);
			$token=$json['token'];
			$output=$this->getContents($_SERVER['DOCUMENT_ROOT'].'/inc/logic_'.$token.'.php');
			return $output;
		}
}


?>